﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<title>节假日设置</title>
    <link href="../../../DataUser/Style/ccbpm.css" rel="stylesheet" type="text/css" />
	<script src="../../Scripts/jquery-1.7.2.min.js" type="text/javascript"></script>
	<script src="../../Scripts/QueryString.js" type="text/javascript"></script>
	<script src="../../Scripts/config.js" type="text/javascript"></script>
	<script src="../Gener.js" type="text/javascript"></script>
	<script src="../../Style/skin/layui/layer.js" type="text/javascript"></script>
	<script type="text/javascript" language="javascript" >
		//枚举值
	    if (typeof DayOfWeek == "undefined") {
	        var DayOfWeek = {}

	        DayOfWeek.Sunday = 0,

			DayOfWeek.Monday = 1,

			DayOfWeek.Tuesday = 2,

			DayOfWeek.Wednesday = 3,

			DayOfWeek.Thursday = 4,

			DayOfWeek.Friday = 5,

			DayOfWeek.Saturday = 6
	    }


		$(function () {
			//系统设置
			var gloVar = new Entity("BP.Sys.GloVar");
			gloVar.No = "Holiday";
			gloVar.RetrieveFromDBSources();

			//获取当前时间
			var dt = new Date();
			while (dt.getDay() != DayOfWeek.Sunday)
				dt.setDate(dt.getDate() - 1);
			var htm = "";
			var idx = 0;
			while (true) {

				var text = getFullMonth(dt.getMonth()+1) + "月" + getFullDay(dt.getDate()) + "日";
				var id = getFullMonth(dt.getMonth()+1) + "-" + getFullDay(dt.getDate());
				var checked = "";
				if (gloVar.Val.indexOf(id) >= 0)
					checked = "checked='checked'";


				switch (dt.getDay()) {
					case DayOfWeek.Sunday:
						idx++;
						htm += "<tr>";
						htm += "<td class='Idx' nowrap>" + idx + "</td>";
						htm += "<td nowrap >" + (dt.getMonth() + 1 )+ "月</td>";
						htm += "<td  nowrap   ><input id='" + id + "' type='checkbox' name='" + id + "'" + checked + " /><label for='" + id + "'>" + text + "</label></td>";

						break;
					case DayOfWeek.Saturday:
						htm += "<td  nowrap   ><input id='" + id + "' type='checkbox' name='" + id + "'" + checked + " /><label for='" + id + "'>" + text + "</label></td>";
						htm += "</tr>";
						break;
					default:
						htm += "<td  nowrap class='TRSum'  ><input id='" + id + "' type='checkbox' name='" + id + "'" + checked + " /><label for='" + id + "'>" + text + "</label></td>";
						break;
				}

				if (dt.getFullYear() != new Date().getFullYear())
					break;

				dt.setDate(dt.getDate() + 1);

			}
			$("#HolidayTab").append(htm);
			$("#showMsg").html("");
		});
		function getFullMonth(month) {
			if (month >= 1 && month <= 9) {
				month = "0" + month;
			}
			return month;
		}
		function getFullDay(data) {
			if (data >= 0 && data <= 9) {
				data = "0" + data;
			}
			return data;
		}

		function saveData() {
		    var str = "";
		    var inputArray = $("input[type='checkbox']"); //取到所有的input 并且放到一个数组中  
		    inputArray.each(//使用数组的循环函数 循环这个input数组  
				function () {
				    var input = $(this); //循环中的每一个input元素  
				    if (input.is(':checked')) {
				        str += input.attr("id") + ","; //查看循环中的每一个input的id
				    }
				});
		    var gloVar = new Entity("BP.Sys.GloVar");
		    gloVar.No = "Holiday";
		    gloVar.RetrieveFromDBSources();
		    gloVar.Val = str;
		    gloVar.Holidays = str;
		    if (gloVar.Save()) {
		        layer.msg('保存成功!', { time: 2000, icon: 1, anim: 5 });
		    } else {
		        layer.msg('保存失败!', { time: 2000, icon: 2, anim: 5 });
		        //window.location.href = window.location.href;
		    }
		}	
	   
	</script>
</head>
<body  >

<form id="cc">
  <table id="HolidayTab"  style="width:80%;" >
	 <caption>节假日设置(请在属于节假日的日期里打勾)</caption>
	 <tr>
	 <th>序</th>
	 <th>月份</th>
	 <th>周日</th>
	 <th>周一</th>
	 <th>周二</th>
	 <th>周三</th>
	 <th>周四</th>
	 <th>周五</th>
	 <th>周六</th>
	 </tr>
</table>
<br />
<center><div id="showMsg"> <img src='../../Img/loading.gif' alt="" />正在加载，请稍后。。。 </center></div>
</form>

<div align="center"><input type="submit" name="Btn_Save" value="保存" onclick="saveData()" id="Btn_Save"/></div>
</body>
</html>
